def solve(nums, val):
    n = len(nums)
    cnt = 0
    res = []
    for i in range(n):
        if nums[i] != val:
            res.append(nums[i])
            cnt += 1

    nums[:cnt] = res #不改变原数组的长度，不改变剩下元素的相对位置
    # nums[:]=res #改变原数组的长度
    return nums


if __name__ == "__main__":
    nums = [3, 2, 2, 3]
    val = 3
    print(solve(nums, val))
